$(function(){

	$.validator.addMethod(
		"parentId",
		function(value, element, param) {
			var leaveCode = $('#js_leaveCode option:selected').val();
			if (leaveCode != '7002') {
				return true;
			}

			var parentId = $('#js_parentId option:selected').val();
			if ($.trim(parentId) != '') {
				return true;
			}

			return false;
		},
		'请选择一级导航' //验证信息
	);

	$("#addForm").validate({
		rules: {
			name: 'required',
			link: {required:true, url:true},
			tank: 'required',
			leaveCode: 'required',
			parentId: {parentId:true}
		},
		messages: {
			name: {
				required: "请输入链接名称"
			},
			link: {
				required: "请输入链接地址"
			},
			tank: {
				required: "请选择是否新窗口打开"
			},
			leaveCode: {
				required: "请选择层级"
			}
		}
	});

	$("#js_leaveCode").change(function(){
		var value = $('#js_leaveCode option:selected').val();
		if (value != '7002') {
			$('#js_parentId').val('');
			$('div.js_parentId_div').addClass('hide');
		} else {
			$('div.js_parentId_div').removeClass('hide');
		}
	});

});